package es.ats.codington.festival.junit;


import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import es.ats.codington.festival.domain.Event;
import es.ats.codington.festival.domain.EventSignUp;
import es.ats.codington.festival.services.EventSignUpService;

import junit.framework.TestCase;

public class TestEventSignUpService extends TestCase{
	
	Connection connection;
	boolean bool;
	EventSignUp e;
	EventSignUpService esu;
	int size;
	List<Event> events;
	
	@Before
	protected void setUp() throws Exception {
		super.setUp();

		e = new EventSignUp(2,1);

		esu = new EventSignUpService();
		events = new ArrayList<Event>();
		size=1;
		
		bool=true;
	}
	
	@After
	protected void tearDown() throws Exception {
		super.tearDown();

	}
	
	@Test
	public void testRegisterVisitorForNewEvent() {
		
		
		
		try {
			if(esu.checkEventsofVisitor(e)==false){
				
				if(esu.checkSeatsAvailable(e)){
					assertEquals(esu.registerVisitorForNewEvent(e),1);
					assertEquals(esu.updateMinusSeatsAvailableEvent(e),true);
				}
				else{
					assertEquals(esu.checkSeatsAvailable(e),false);
				}
				
			}
			else{
				assertEquals(esu.checkEventsofVisitor(e),true);
			}
				
	
		} catch (Exception ex) {
			fail("No exception should be thrown");
		}
		
		
	}
	
	@Test
	public void testViewEventsOfUser() {
		
		
		
		try {
			e.setIdEvent(2);
			e.setIdVisitor(1);
			events=esu.viewEventsOfUser(e);
			assertEquals(events.size(),size);
	
		} catch (Exception ex) {
			fail("No exception should be thrown");
		}
		
		
	}
	
	
	@Test
	public void testCheckEventsofVisitor() {
		
		
		
		try {
			assertEquals(esu.checkEventsofVisitor(e),bool);
	
		} catch (Exception ex) {
			fail("No exception should be thrown");
		}
		
		
	}
	@Test
	public void testUnregisterVisitorForEvent() {
		
		
		
		try {
			assertEquals(esu.unregisterVisitorForEvent(e),1);
			assertEquals(esu.updateSumSeatsAvailableEvent(e),true);
	
		} catch (Exception ex) {
			fail("No exception should be thrown");
		}
		
		
	}
	
	

	
}